fix(renderer): resolve relative .md links against a leaf page's parent dir#573
Merged
Conversation
…t dir Relative `.md` links from a leaf page resolved one directory too deep — `[x](./other.md)` in `docs/specs/notif.md` produced `/specs/notif/other` instead of the sibling `/specs/other` — because the renderer treated every page's clean URL as its containing directory. That is correct only for directory-index pages (`index.md`, the README homepage); a leaf page (`name.md`) resolves relative links against its parent, per CommonMark. Carry an `is_dir` flag from the scanner through Document -> Page -> RenderConfig (true for a directory URL: index.md/README/virtual; false for a leaf file). Apply it as a one-time base-path correction at the link seam: for a leaf page, drop the page's own URL slug before resolving relative links. The RenderBackend trait and the resolver are untouched, and README/`docs/`-prefix homepage links are unchanged. `is_dir` is serde default-true on the serialized Document (S3 bundle) and Page (structure cache) so data written before the field existed deserializes to the prior behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Relative
.mdlinks from a leaf page resolved one directory too deep. For example,[inbox](./inbox.md)indocs/specs/notif.mdproduced/specs/notif/inboxinstead of the sibling/specs/inbox(a 404). The renderer treated every page's clean URL as its containing directory — correct for directory-index pages (index.md, the README homepage), but wrong for leafname.mdpages, whose siblings live in the parent directory. Per CommonMark,./sibling.mdis a sibling of the source file.Fix
Carry an
is_dirflag from the scanner throughDocument→Page→RenderConfig:truefor a directory URL (index.md, README homepage, virtual page)falsefor a leaf file (name.md)It's applied as a one-time base-path correction at the existing link seam (beside
strip_origin, beforetransform_link): for a leaf page, the page's own URL slug is dropped before relative links resolve. The genericRenderBackendtrait and the resolver are untouched, and README /docs/-prefix homepage links are unchanged.is_diris#[serde(default = true)]on the serializedDocument(S3 bundle) andPage(structure cache), so data written before the field existed deserializes to the prior behavior — no migration needed.Behavior
Leaf page
specs/notif.md(URL/specs/notif):./inbox.md/specs/inbox../x.md/xsub/y.md/specs/sub/yIndex page
specs/notif/index.md(URL/specs/notif) is unchanged (./inbox.md→/specs/notif/inbox).Testing
index.md→ dir, leaf → file) and README-homepage assertionDocument/Pageserde-default backward-compat testsrw-sitetest through the realFsStoragescannerrw serveagainst a real docs tree: the two previously-broken links now resolve to their sibling pages (200)🤖 Generated with Claude Code